package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    ApArticleService apArticleService;



    /**
     * 保存app文章
     * @param articleDto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto articleDto) {
        return apArticleService.saveArticle(articleDto);
    }


    @GetMapping("/one/{id}")
    public ApArticle findArticleById(@PathVariable("id") Long articleId) {
        return apArticleService.getById(articleId);
    }

    @PutMapping("/updateArticleById")
    public void updateArticleById(@RequestBody ApArticle article) {
        apArticleService.updateById(article);  // article 必须有staticUrl
    }

}
